
import { cloneDeep } from 'lodash'
import { cityCode } from '@/utils/cityPicker/cityCode'

export default {
  name: 'HelloWorld',
  data () {
    return {
      options: cityCode, // 城市信息
      htmlTitle: '简历',
      msg: 'Welcome to Your Vue.js App',
      isEditBasicInfo: false, // 是否编辑基本信息
      form: {
        name: '',
        date: '', // 出生日期
        wYears: '', // 工作年限
        isShowPortrait: '1', // 是否显示头像
        phone: '',
        email: '',
        isNotshowDescribe: false, // 是否显示描述
        describe: '' // 描述
      },
      showForm: {
        name: '姓名',
        date: '1998-7-7', // 出生日期
        wYears: '12', // 工作年限
        isShowPortrait: '1',
        phone: '13211112222',
        email: '123@qq.com',
        isNotshowDescribe: false, // 是否显示描述
        describe: '一句话描述'
      },
      form1: {
        occupation: '', // 职业
        city: '', // 城市
        joinTime: '', // 入职时间
        wages: '' // 薪水
      },
      showForm1: {
        occupation: '', // 职业
        city: '', // 城市
        joinTime: '', // 入职时间
        wages: '' // 薪水
      },
      showForm3: [
        {
          date: '',
          company: '',
          position: '',
          detail: ''
        }
      ], // 工作经验
      showForm5: [
        {
          date: '',
          school: '',
          major: '',
          detail: ''
        }
      ], // 教育经历
      showForm6: [
        {
          date: '',
          project: '',
          role: '',
          detail: ''
        }
      ], // 项目经验
      isEditPurpose: false, // 是否编辑求职意向
      isEditWorkExperience: false, // 是否编辑工作经验
      isEditStudyExperience: false, // 是否编辑学习经验
      isEditSkill: false, // 是否编辑技能特长
      isAddSkill: false, // 是否添加技能特长
      isEditProjectExperience: false, // 是否编辑项目经验
      selfIntroduction: '', // 自我介绍
      isShowPurpose: true, // 是否显示求职意向
      isShowWorkExperience: true, // 是否显示工作经历
      isShowStudyExperience: true, // 是否显示学习经历
      isShowSkill: true, // 是否显示技能特长
      isShowProjectExperience: true, // 是否显示项目经验
      isShowIntroduction: true, // 是否显示自我介绍
      skill: '', // 自定义技能
      skills: [
        {
          value: 0,
          name: '团队协作精神',
          isChecked: false
        },
        {
          value: 1,
          name: '学习能力',
          isChecked: false
        },
        {
          value: 2,
          name: '责任感',
          isChecked: false
        },
        {
          value: 3,
          name: '沟通能力',
          isChecked: false
        },
        {
          value: 4,
          name: '执行能力',
          isChecked: false
        },
        {
          value: 5,
          name: '人际关系处理',
          isChecked: false
        },
        {
          value: 6,
          name: '承受压力',
          isChecked: false
        },
        {
          value: 7,
          name: '自我管理',
          isChecked: false
        }
      ], // 默认技能特长
      selSkills: [], // 选中的技能
      skillLevel: 0,
      drawer: false,
      pickerOptions1: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      workYears: [
        {
          value: 0,
          name: '应届生'
        },
        {
          value: 1,
          name: '1年经验'
        },
        {
          value: 2,
          name: '2年经验'
        },
        {
          value: 3,
          name: '3年经验'
        },
        {
          value: 4,
          name: '4年经验'
        },
        {
          value: 5,
          name: '5年经验'
        },
        {
          value: 6,
          name: '6年经验'
        },
        {
          value: 7,
          name: '7年经验'
        },
        {
          value: 8,
          name: '8年经验'
        },
        {
          value: 9,
          name: '9年经验'
        },
        {
          value: 10,
          name: '10年经验'
        },
        {
          value: 11,
          name: '10年以上'
        }
      ],
      joinWorkYears: [
        {
          value: 0,
          name: '随时到岗'
        },
        {
          value: 1,
          name: '1周内到岗'
        },
        {
          value: 2,
          name: '1个月内到岗'
        },
        {
          value: 3,
          name: '3个月内到岗'
        },
        {
          value: 4,
          name: '到岗时间另议'
        },
        {
          value: 5,
          name: '不填写'
        }
      ]
    }
  },
  methods: {
    // 编辑基础信息
    editBasicInfo () {
      this.form = cloneDeep(this.showForm)
      this.isEditBasicInfo = true
    },
    // 更新基础信息
    updateBasicInfo () {
      this.showForm = cloneDeep(this.form)
      this.isEditBasicInfo = false
    },
    // 编辑求职意向
    editPurpose () {
      this.form1 = cloneDeep(this.showForm1)
      this.isEditPurpose = true
    },
    // 更新求职意向
    updatePurpose () {
      this.showForm1 = cloneDeep(this.form1)
      this.isEditPurpose = false
    },
    // 添加工作经验
    addWorkExperience () {
      this.showForm3.push(
        {
          date: '',
          company: '',
          position: '',
          detail: ''
        }
      )
    },
    // 删除工作经验
    delWorkExperience (index) {
      this.showForm3.splice(index, 1)
    },
    // 清空工作经验
    clearWorkExperience () {
      this.showForm3 = [
        {
          date: '',
          company: '',
          position: '',
          detail: ''
        }
      ]
    },
    // 添加学习经验
    addStudyExperience () {
      this.showForm5.push(
        {
          date: '',
          school: '',
          major: '',
          detail: ''
        }
      )
    },
    // 删除学习经验
    delStudyExperience (index) {
      this.showForm5.splice(index, 1)
    },
    // 清空学习经验
    clearStudyExperience () {
      this.showForm5 = [
        {
          date: '',
          school: '',
          major: '',
          detail: ''
        }
      ]
    },
    // 添加项目经验
    addProjectExperience () {
      this.showForm6.push(
        {
          date: '',
          project: '',
          role: '',
          detail: ''
        }
      )
    },
    // 删除项目经验
    delProjectExperience (index) {
      this.showForm6.splice(index, 1)
    },
    // 清空项目经验
    clearProjectExperience () {
      this.showForm6 = [
        {
          date: '',
          project: '',
          role: '',
          detail: ''
        }
      ]
    },
    // 添加技能
    addSkill () {
      if (this.selSkills.length >= 10) {
        this.$message({
          message: '不能再添加了',
          type: 'warning'
        })
        return
      }
      if (this.skill) {
        this.selSkills.push({
          name: this.skill,
          skillLevel: 0
        })
        this.skill = ''
      }
    },
    // 更新技能
    updateSkill () {
      this.isAddSkill = false
    },
    // 删除技能
    delSkill (index, name) {
      this.selSkills.splice(index, 1)
      this.skills.forEach((item, indexs) => {
        if (name === item.name) {
          this.skills[indexs].isChecked = false
        }
      })
    },
    // 清空技能
    clearSkill () {
      this.selSkills = []
    },
    // 选中默认技能
    chooseSkill (index) {
      if (!this.skills[index].isChecked) {
        if (this.selSkills.length >= 10) {
          this.$message({
            message: '不能再添加了',
            type: 'warning'
          })
          return
        }
        this.skills[index].isChecked = true
        this.selSkills.push({
          name: this.skills[index].name,
          skillLevel: 0
        })
      } else {
        this.skills[index].isChecked = false
        this.selSkills = this.selSkills.filter((item) => {
          return item.name !== this.skills[index].name
        })
      }
    },
    handleBodyClick () {
      if (this.isEditWorkExperience) {
        this.isEditWorkExperience = false
      }
      if (this.isEditSkill) {
        this.isEditSkill = false
      }
      if (this.isEditStudyExperience) {
        this.isEditStudyExperience = false
      }
      if (this.isEditProjectExperience) {
        this.isEditProjectExperience = false
      }
    }
  },
  mounted () {
    this.$nextTick(() => {
      document.querySelector('body').addEventListener('click', this.handleBodyClick)
    })
  },
  beforeDestroy () {
    document.querySelector('body').removeEventListener('click', this.handleBodyClick)
  },
  filters: {
    getLevel (level) {
      let newLevel = ''
      switch (level) {
        case 0:
          newLevel = '略懂'
          break
        case 25:
          newLevel = '一般'
          break
        case 50:
          newLevel = '良好'
          break
        case 75:
          newLevel = '熟练'
          break
        case 100:
          newLevel = '精通'
          break
        default:
          break
      }
      return newLevel
    },
    getCityText (city) {
      if (!city) {
        return '意向城市'
      } else if (city[0] === city[1]) {
        return city[0]
      } else {
        return `${city[0]} ${city[1]}`
      }
    }
  }
}
